#include "simplysupported.h"
#include <vector>

SimplySupported::~SimplySupported()
{
    //dtor
}

//SimplySupported Constructor
SimplySupported::SimplySupported(int BeamLength, int LeftSupportLocation, int RightSupportLocation)
{
    SetLength(BeamLength);
    m_RightSupportLocation = RightSupportLocation;
    m_LeftSupportLocation = LeftSupportLocation;
}

/*
	Params LoadValue (int)
        LoadLocation (int)
        This will load the beam with the loads specified in the xml file.
*/
void SimplySupported::AddLoads(int LoadValue, int LoadLocation)
{
    AddBeamLoad(LoadValue, LoadLocation);
}


/*
  Return the reaction at the right support
  For simplicity this will return an integer
  This will calculate the moment around the left support to find the remaining reaction at the right support.
*/
int SimplySupported::GetRightSupportReaction()
{
    int AllLoadingsMoments = 0;

    std::vector<Loadings>::iterator BeamLoadings;
    for(BeamLoadings = m_loads.begin(); BeamLoadings != m_loads.end(); ++BeamLoadings)
    {
        AllLoadingsMoments += (BeamLoadings->GetLoadLocation() * BeamLoadings->GetLoadValue());
    }

    int SupportLocation = SimplySupported::m_RightSupportLocation;

    //The -1 is to account for the -force being the downward direction.  This hopefully will cause the reaction force to be reported correctly.
    int ReactionB = (-1 * AllLoadingsMoments) / SupportLocation;

    return ReactionB;
}


/*
	This will find the reaction at the left support using the reaction at the right support and the beam loadings
	For simplicities sake this returns an integer.
*/
int SimplySupported::GetLeftSupportReaction()
{
    int ReactionB = GetRightSupportReaction();
    int AllLoads = 0;
    std::vector<Loadings>::iterator BeamLoadings;
    for(BeamLoadings = m_loads.begin(); BeamLoadings != m_loads.end(); ++BeamLoadings)
    {
        AllLoads += BeamLoadings->GetLoadValue();
    }

    int ReactionA = (-1 * AllLoads) - ReactionB;

    return ReactionA;
}
